<template>
  <el-dialog
    title="关联中介"
    :visible.sync="dialogValue"
    width="1000px"
  >
    <div class="title">选择中介：</div>
    <div class="search-params f-r a-c j-b">
      <el-form inline>
        <el-form-item label="中介单位名称：">
          <el-input v-model="searchParams.corporateName" clearable />
        </el-form-item>
        <el-form-item label="单位代码：">
          <el-input v-model="searchParams.creditCode" clearable />
        </el-form-item>

        <el-form-item label="中介联系人：">
          <el-input v-model="searchParams.contactsName" clearable />
        </el-form-item>
        <el-form-item label="中介联系人手机：">
          <el-input v-model="searchParams.contactsPhone" clearable />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" round @click="onSearch">筛选</el-button>
          <el-button round @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="table-box">
      <el-table
        ref="tableRef"
        v-loading="loading"
        height="400px"
        stripe
        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >
        <el-table-column type="index" width="80px" label="序号" align="center" />
        <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label" align="center" />
        <el-table-column label="操作" fixed="right" width="120px">
          <template slot-scope="scope">
            <el-button type="text" @click="onConfirmRel(scope.row)">关联</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>
  </el-dialog>
</template>

<script>
import crud from '@/mixins/crud'
import { http_intermediary_app, http_intermediary_info } from '@/api'

export default {
  name: 'User1Add',
  mixins: [crud],
  data() {
    return {
      request: http_intermediary_info,
      searchParams: {},
      columns: [
        { prop: 'creditCode', label: '单位代码' },
        { prop: 'corporateName', label: '中介名称' },
        { prop: 'contactsName', label: '中介联系人' },
        { prop: 'contactsPhone', label: '中介联系人手机' },
        { prop: 'officeLocation', label: '办公地址' }
      ],
      apId: ''
    }
  },
  methods: {
    open(item) {
      this.apId = item.id
      this.dialogValue = true

      this.$nextTick(() => {
        this.$refs.tableRef.doLayout()
      })
    },
    onConfirmRel(item) {
      http_intermediary_app.rel({
        id: this.apId,
        intermediaryId: item.id
      }).then(res => {
        this.$message.success(res.msg)
        this.dialogValue = false
        this.$emit('get-page')
      })
    }
  }
}
</script>
<style scoped>
.title {
  color: #333333;
  font-size: 24px;
    line-height: 48px;
}
</style>
